package com.service;

import com.websocket.wsSyncClient;

import java.sql.SQLException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 开启同步服务
 * @author zyf
 */
public class SyncServiceTest {
    public static void main(String[] args) {
        String host = "192.168.2.69:8081";
        String propsPath = "conf/database.properties";
        SyncService syncService = new SyncService("repchain",propsPath);
        wsSyncClient syncClient = new wsSyncClient(host);
        syncClient.createObserverList();
        syncClient.registerObserver(syncService);
        try {
            syncClient.connectBlocking();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        while (syncClient.getConnection().isOpen()) { }
        syncClient.getConnection().close();
        ExecutorService executorService = syncService.getExecutor();
        executorService.shutdown();
        try {
            while (!executorService.awaitTermination(1, TimeUnit.SECONDS)) {
                System.out.println("线程还在执行");
            }
//            syncService.getConn().close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
